<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active {
      color: red
    }

    .bbb {
      color: green;
    }

    .ccc {
      color: blue
    }
  </style>
</head>

<body>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="app">
    {{ count }}
    <button @click="increment">点击</button>
    <p> 计算属性： {{ getTitle}}</p>
    <p> 方法： {{ fnTitle() }}</p>
    <p :class="{ active: isActive, 'aaa':  isActive }">动态绑定clsss</p>
    <p :class="classObj1">动态绑定clsss 对象1</p>
    <p :class="classObj2">动态绑定clsss 对象2</p>
    <p :class="['bbb', 'ccc']">动态绑定clsss 数组</p>
    <p :class="[isActive ? 'active' : '', 'aaa']">动态绑定clsss 数组</p>
    <p v-if="isActive">v-if</p>
    <p v-if="isActive">v-show</p>
    <!-- v-if 优先级高于v-for  同一原素上 -->
    <p v-if="isActive" v-for="i in 2">{{i}}</p>
    <p v-for="{msg} in lowData">{{msg}}</p>
    <p v-for="{msg} of lowData">{{msg}}</p>
    <p v-for="(value, key, index ) in myObj">{{key}} {{value}} {{index}}</p>
    <span v-for="n in 10">{{ n }}</span>
  </div>

  <script>
    const { createApp } = Vue

    createApp({
      data () {
        return {
          message: 'Hello Vue!',
          count: 0,
          isActive: false,
          lowData: [
            { msg: '数据1' },
            { msg: '数据2' },

          ],
          myObj: {
            title: '表题',
            author: '作者',
            date: '日期'
          },
        }
      },
      computed: {
        classObj1 () {
          let claaName = 'ccc'
          this.isActive ? claaName = "bbb" : 0
          return claaName
        },

        classObj2 () {
          return {
            ccc: this.isActive,
          }
        },


        getTitle () {
          console.log('计算属性');
          let isEvenNumber = this.count % 2
          // console.log('isEvenNumber: ', isEvenNumber);
          if (isEvenNumber) {
            return '你好'
          } else {
            return '我不好'
          }
        }
      },
      mounted () {
        console.log(this.message)
      },
      watch: {
        isActive: {
          handler (newQuestion) {
            console.log('newQuestion: ', newQuestion);
            // 在组件实例创建时会立即调用
          },
          // 强制立即执行回调
          immediate: true
        }
      },
      methods: {


        fnTitle () {
          console.log('方法');

          let isEvenNumber = this.count % 2
          // console.log('isEvenNumber: ', isEvenNumber);
          if (isEvenNumber) {
            return '你好'
          } else {
            return '我不好'
          }
        },

        increment () {
          this.$nextTick(() => {
            // console.log('this.count: ', this.count);
          })
          this.count++
          this.isActive = !this.isActive
        },


      }
    }).mount('#app')
  </script>

</body>

</html>